package com.eportal.struts.interceptor;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class TimerInterceptor extends AbstractInterceptor {
		    private static final long serialVersionUID = 6017311502566041661L;
		    private static final Log log = LogFactory.getLog(TimerInterceptor.class);
		    public String intercept(ActionInvocation invocation) throws Exception {
		
		        long startTime = System.currentTimeMillis();//���㿪ʼ����
		        String result = invocation.invoke();
		        long executionTime = System.currentTimeMillis() - startTime;
		
		        StringBuffer message = new StringBuffer(100);
		        message.append("Executed action [");
		        String namespace = invocation.getProxy().getNamespace();
		        if ((namespace != null) && (namespace.trim().length() > 0)) {
		           message.append(namespace).append("/");
		        }
		        message.append(invocation.getProxy().getActionName());
		        message.append("!");
	            message.append(invocation.getProxy().getMethod());
		        message.append("] took ").append(executionTime).append(" ms.");
		
		        if (log.isInfoEnabled()) {
		            log.info(message.toString());
		            if(invocation.getProxy().getMethod().equals("importExcel")){
		            	return "importExcel";
		            }
		        }
		
		        return result;
		
		   }
}
